package com.globussoft.filesystem;

import java.io.*;
import java.util.HashMap;
import javax.swing.JTable;

/* code for getting the filelist on the fileTable*/
public class FileList extends JTable {

    HashMap hm_all_sub_sub_direct = new HashMap();
    HashMap hm_all_files = new HashMap();
    int file_count = 0;
    int dir_count = 1;

    public void getAllDirectoty(String filePath) {
        filePath = filePath.trim();
        File[] file;
        file = new File(filePath).listFiles();
        if (file != null) {
            for (int i = 0; i < file.length; i++) {

            //    System.out.println(file[i] + "is  File" + file[i].isFile());
           //     System.out.println(file[i] + "is  Dir" + file[i].isDirectory());
                if (file[i].isFile() && file[i].isHidden() == false) {
               //     System.out.println("file $$$ :" + file[i].getPath());
                    String file_path_f = file[i].getPath();
                    hm_all_files.put(file_count, file_path_f);
                    file_count++;
                } else if (file[i].isDirectory()) {
                    String file_path_d = file[i].getPath();
            //        System.out.println("Dir  :" + file_path_d);
                    hm_all_sub_sub_direct.put(dir_count, file_path_d);
                    //System.out.println(hm_all_sub_sub_direct.size()+" "+dir_count);
                    dir_count++;
                }

            }

        }

    }

    public HashMap setRootDir(String filename) {
      //  System.out.println("fileName" + filename);
        hm_all_sub_sub_direct.put(0, filename);
        int count = 0;
//                 while(!hm_all_sub_sub_direct.isEmpty())
//                 {
//                     try{
        getAllDirectoty(hm_all_sub_sub_direct.remove(count).toString());
//                     }catch(Exception ex){}
//                     count++;
//                 }
    //    System.out.println(hm_all_files.size());
        return hm_all_files;
    }
}
